package com.huatai.exchange.utils;

import com.faneui.common.exception.BusinessException;
import com.faneui.common.utils.ListUtils;
import com.faneui.dal.DBUtils;
import com.faneui.service.Dbconfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.sql.Connection;
import java.util.List;
import java.util.Map;

@Component
public class GzFundUtils {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    public String getFundName(String ztbh) throws BusinessException {
        Connection conn = null;
        String user = "facx";
        String r;
        try {
            conn = DBUtils.getConnection(Dbconfig.FATADB, user, Dbconfig.getPasswordByUserId(user));
            String sql = "select vc_name from hsfa.tfundinfo where l_fundid = ? ";
            List<Map<String, Object>> result = DBUtils.executeQuery(conn, sql, ztbh);
            if (ListUtils.isEmpty(result)) {
                r = "";
            } else {
                r = (String) result.get(0).get("VC_NAME");
            }
        } catch (Exception ex) {
            logger.error("", ex);
            r = ex.getMessage();
        } finally {
            DBUtils.closeAll(conn);
        }
        return r;
    }

    public String getFundNameByFundCode(String fundCode) throws BusinessException {
        Connection conn = null;
        String user = "facx";
        String r;
        try {
            conn = DBUtils.getConnection(Dbconfig.FATADB, user, Dbconfig.getPasswordByUserId(user));
            String sql = "select vc_name from hsfa.tfundinfo where vc_code = ? ";
            List<Map<String, Object>> result = DBUtils.executeQuery(conn, sql, fundCode);
            if (ListUtils.isEmpty(result)) {
                r = "";
            } else {
                r = (String) result.get(0).get("VC_NAME");
            }
        } catch (Exception ex) {
            logger.error("", ex);
            r = ex.getMessage();
        } finally {
            DBUtils.closeAll(conn);
        }
        return r;
    }
}
